package com.dzm.xgb.core.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dzm.common.result.R;
import com.dzm.xgb.core.pojo.entity.UserInfo;
import com.dzm.xgb.core.pojo.entity.UserLoginRecord;
import com.dzm.xgb.core.pojo.vo.SearchVo;
import com.dzm.xgb.core.service.UserInfoService;
import com.dzm.xgb.core.service.UserLoginRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：Dzm
 * 时间：2024-09-03-10:11
 * 功能：
 */

@Api(tags = "会员管理")
@RestController
@RequestMapping("/admin/core/userInfo")
@Slf4j
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private UserLoginRecordService userLoginRecordService;

    @ApiOperation("用户查询")
    @PostMapping("/search/{pageNum}/{pageSize}")
    public R searchPage(@PathVariable("pageNum") Integer pageNum,
                        @PathVariable("pageSize") Integer pageSize,
                        @RequestBody SearchVo vo) {
        Page<UserInfo> pageModel = userInfoService.searchPage(pageNum, pageSize, vo);

        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation("修改用户锁状态")
    @PutMapping("/lock/{id}/{status}")
    public R lock(@PathVariable("id") Long id,
                  @PathVariable("status") Integer status) {
        userInfoService.lock(id, status);

        return R.ok().message(status == 1?"解锁成功！":"锁定成功！");
    }

    @ApiOperation("查询用户的登录日志")
    @GetMapping("/userLoginRecord/{id}")
    public R userLoginRecord(@PathVariable("id") Integer id) {
        List<UserLoginRecord> list = userLoginRecordService.listByUserId(id);

        return R.ok().data("list", list);
    }
}
